package com.custom.action.condition;

import com.custom.comm.enums.DbSymbol;
import com.custom.comm.enums.SqlLike;

import java.util.Collection;

/**
 * @author XiaoBai
 * @since 2024/3/10 0010 14:37
 */
public abstract class  AbstractConditionWrapper<T, Param, Children> extends ConditionAdapter<T, Param, Children>
        implements Wrapper<Param, Children> {


    @Override
    protected Children adapter(boolean condition, DbSymbol dbSymbol, Param column) {
        appendCondition(dbSymbol, condition, paramTransColumn(column), null, null, null);
        return childrenClass;
    }


    @Override
    protected Children adapter(DbSymbol dbSymbol, boolean condition, String columnSql) {
        appendCondition(dbSymbol, condition, columnSql, null, null, columnSql);
        return childrenClass;
    }


    @Override
    protected Children adapter(DbSymbol dbSymbol, boolean condition, Param column, Object val) {
        appendCondition(dbSymbol, condition, paramTransColumn(column), val, null, null);
        return childrenClass;
    }


    @Override
    protected Children adapter(DbSymbol dbSymbol, boolean condition, Param column, Object val1, Object val2) {
        appendCondition(dbSymbol, condition, paramTransColumn(column), val1, val2, null);
        return childrenClass;
    }


    @Override
    protected Children adapter(DbSymbol dbSymbol, boolean condition, Param column, String expression) {
        appendCondition(dbSymbol, condition, paramTransColumn(column), null, null, expression);
        return childrenClass;
    }

    @Override
    public Children eq(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.EQUALS, condition, column, val);
    }

    @Override
    public Children ne(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.NOT_EQUALS, condition, column, val);
    }

    @Override
    public Children ge(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.GREATER_THAN_EQUALS, condition, column, val);
    }

    @Override
    public Children le(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.LESS_THAN_EQUALS, condition, column, val);
    }

    @Override
    public Children lt(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.LESS_THAN, condition, column, val);
    }

    @Override
    public Children gt(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.GREATER_THAN, condition, column, val);
    }

    @Override
    public Children in(boolean condition, Param column, Collection<?> val) {
        return adapter(DbSymbol.IN, condition, column, val);
    }

    @Override
    public Children inSql(boolean condition, Param column, String inSql, Object... params) {
        appendInSql(paramTransColumn(column), DbSymbol.IN, inSql, params);
        return childrenClass;
    }

    @Override
    public Children notIn(boolean condition, Param column, Collection<?> val) {
        return adapter(DbSymbol.NOT_IN, condition, column, val);
    }

    @Override
    public Children notInSql(boolean condition, Param column, String inSql, Object... params) {
        appendInSql(paramTransColumn(column), DbSymbol.NOT_IN, inSql, params);
        return childrenClass;
    }

    @Override
    public Children exists(boolean condition, String existsSql) {
        return adapter(DbSymbol.EXISTS, condition, existsSql);
    }

    @Override
    public Children notExists(boolean condition, String notExistsSql) {
        return adapter(DbSymbol.NOT_EXISTS, condition, notExistsSql);
    }

    @Override
    public Children like(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.LIKE, condition, column, val, SqlLike.LIKE);
    }

    @Override
    public Children notLike(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.NOT_LIKE, condition, column, val, SqlLike.LIKE);
    }

    @Override
    public Children likeLeft(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.LIKE, condition, column, val, SqlLike.LEFT);
    }

    @Override
    public Children likeRight(boolean condition, Param column, Object val) {
        return adapter(DbSymbol.LIKE, condition, column, val, SqlLike.RIGHT);
    }

    @Override
    public Children between(boolean condition, Param column, Object val1, Object val2) {
        return adapter(DbSymbol.BETWEEN, condition, column, val1, val2);
    }

    @Override
    public Children notBetween(boolean condition, Param column, Object val1, Object val2) {
        return adapter(DbSymbol.NOT_BETWEEN, condition, column, val1, val2);
    }

    @Override
    public Children isNull(boolean condition, Param column) {
        adapter(condition, DbSymbol.IS_NULL, column);
        return childrenClass;
    }

    @Override
    public Children isNotNull(boolean condition, Param column) {
        return adapter(condition, DbSymbol.IS_NOT_NULL, column);
    }


}
